/**
 * Spark创作状态管理类型定义
 */

import {
  SparkCreationData,
  SparkDialogState,
  ArticleOutline,
  ContentGenerationState,
  DialogStep,
  OutlineSection
} from '../../../types/spark'
import { AIError } from '../../../services/ai/types'

/**
 * Spark创作视图状态
 */
export interface SparkCreationViewState {
  // 当前创作会话
  currentSession: SparkCreationData | null
  
  // 对话状态
  currentDialogStep: DialogStep | null
  
  // 当前大纲
  currentOutline: ArticleOutline | null
  
  // 生成状态
  generationState: ContentGenerationState
  
  // UI状态
  isDialogOpen: boolean
  isGenerating: boolean
  
  // 错误状态
  error: AIError | null
  
  // 加载状态
  isLoading: boolean
  
  // 缓存的创作会话列表
  recentSessions: SparkCreationData[]
}

/**
 * Spark创作操作接口
 */
export interface SparkCreationActions {
  // 创作流程控制
  startSpark: (sparkInput: string) => Promise<void>
  continueDialog: (response: string) => Promise<void>
  resetDialog: () => void
  
  // 大纲操作
  generateOutline: () => Promise<void>
  updateOutline: (outline: ArticleOutline) => void
  updateSection: (sectionId: string, updates: Partial<OutlineSection>) => void
  
  // 内容生成
  generateSectionContent: (sectionId: string) => Promise<void>
  regenerateSectionContent: (sectionId: string) => Promise<void>
  generateFullArticle: () => Promise<void>
  
  // 会话管理
  saveSession: () => Promise<void>
  loadSession: (sessionId: string) => Promise<void>
  deleteSession: (sessionId: string) => Promise<void>
  listRecentSessions: () => Promise<void>
  
  // UI控制
  openDialog: () => void
  closeDialog: () => void
  
  // 错误处理
  clearError: () => void
  
  // 内容输出
  exportToEditor: (content: string) => void
}

/**
 * Spark创作上下文值
 */
export interface SparkCreationContextValue {
  state: SparkCreationViewState
  actions: SparkCreationActions
}

/**
 * Spark创作配置
 */
export interface SparkCreationConfig {
  // AI服务配置
  aiConfig: {
    apiKey: string
    model: string
    temperature: number
    maxTokens: number
  }
  
  // Token预算控制
  tokenBudget: number
  
  // 默认大纲设置
  defaultOutlineSettings: {
    sectionsCount: number
    defaultSectionLength: number
  }
  
  // 自动保存设置
  autoSave: boolean
  autoSaveInterval: number
}